package com.chuanyang.driverh.mainhome.adapter;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseListAdapter;
import com.chuanyang.driverh.mainhome.WaybilDetailActivity;
import com.chuanyang.driverh.mainhome.WaybilDetailDirverActivity;
import com.chuanyang.driverh.mainorder.SureUnLoadOverActivity;
import com.chuanyang.driverh.mainother.BeforeNaviActivity;
import com.chuanyang.driverh.response2.ResultMoneyFollow;
import com.chuanyang.driverh.response2.ResultWaitTransDriver;
import com.chuanyang.driverh.responseresult.LookWaybillData;
import com.chuanyang.driverh.responseresult.OrderAddressResult;
import com.chuanyang.driverh.responseresult.Result;
import com.chuanyang.driverh.responseresult.ValidateCodeResult;
import com.chuanyang.driverh.utils.ConstUtil;
import com.chuanyang.driverh.utils.DialogUtil;
import com.chuanyang.driverh.utils.PrintUtil;
import com.chuanyang.driverh.utils.SharedPrefUtil;
import com.chuanyang.driverh.utils.StringUtil;
import com.chuanyang.driverh.utils.eventbus.EventBusUtil;
import com.chuanyang.driverh.utils.eventbus.RefleshFragEvent;
import com.chuanyang.driverh.utils.net.JsonGenericsSerializator;
import com.chuanyang.driverh.utils.net.MyCallback;
import com.chuanyang.driverh.utils.net.MyHttpUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;

import static com.chuanyang.driverh.R.id.tv_bid_price;
import static com.chuanyang.driverh.R.id.tv_xiadan;


public class WaybillListAdapter extends BaseListAdapter<LookWaybillData.DataBean> {
    private Activity activity;
//    ResultWaitTransDriver.OutDataEntity.DataEntity orderEntity;

    private AlertDialog alertDialog;
    private EditText et_sureunload_code;
    private TextView tv_cancle_unload;
    private TextView tv_sureunload_getcode;
    private TextView tv_sure_unload;
    private boolean validateOk;
    private ArrayList<File> files;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1://确认收货（运单）
                    updateWaybillUnload((String) msg.obj,true);
                    break;
                case 2://确认收货(订单
                    updteOrderUnload((String) msg.obj);
                    break;
            }
        }
    };

//    public void setData(ResultWaitTransDriver.OutDataEntity.DataEntity data) {
//        this.orderEntity = data;
//    }

//    private String start,end="";

//    public void setBegin(String begin) {
//        this.start=begin;
//    }
//    public void setEnd(String end) {
//        this.end=end;
//    }
    ResultWaitTransDriver.OutDataEntity.DataEntity resultWaitTransEntity;

    public void setResultWaitTransEntity(ResultWaitTransDriver.OutDataEntity.DataEntity resultWaitTransEntity) {
        this.resultWaitTransEntity = resultWaitTransEntity;
    }

    public WaybillListAdapter(Activity activity) {
        super(activity);//此处不传入集合，则默认集合长度为0，在setdataresult（）方法中，添加数据并刷新
        this.activity = activity;
    }

    @Override
    public View getZkView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = getInflater().inflate(R.layout.home_item_wayblil_list_loction, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.ll_div = (LinearLayout) convertView.findViewById(R.id.ll_div);
//            viewHolder.line_left = convertView.findViewById(R.id.line_left);
//            viewHolder.tv_order_status = (TextView) convertView.findViewById(R.id.tv_order_status);
            viewHolder.iv_status = (ImageView) convertView.findViewById(R.id.iv_status);
            viewHolder.tv_order_no = (TextView) convertView.findViewById(R.id.tv_order_no);
            viewHolder.tv_order_time = (TextView) convertView.findViewById(R.id.tv_order_time);
            viewHolder.tv_city_start = (TextView) convertView.findViewById(R.id.tv_city_start);
            viewHolder.tv_city_end = (TextView) convertView.findViewById(R.id.tv_city_end);
//            viewHolder.tv_goods_name = (TextView) convertView.findViewById(R.id.tv_goods_name);
//            viewHolder.tv_weight = (TextView) convertView.findViewById(R.id.tv_weight);
            viewHolder.tv_cenyunren = (TextView) convertView.findViewById(R.id.tv_cenyunren);
            viewHolder.tv_acture_weight = (TextView) convertView.findViewById(R.id.tv_acture_weight);
            viewHolder.tv_money = (TextView) convertView.findViewById(R.id.tv_money);
            viewHolder.ll_acture = (LinearLayout) convertView.findViewById(R.id.ll_acture);

            viewHolder.tv_xiadan = (TextView) convertView.findViewById(tv_xiadan);
            viewHolder.tv_bid_price = (TextView) convertView.findViewById(tv_bid_price);
            viewHolder.tv_navi = (TextView) convertView.findViewById(R.id.tv_navi);
            viewHolder.tv_trans = (TextView) convertView.findViewById(R.id.tv_trans);
            viewHolder.tv_gua_name = (TextView) convertView.findViewById(R.id.tv_gua_name);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();

        }
        final LookWaybillData.DataBean data = getItem(position);
        /*viewHolder.line_left.setBackgroundColor(activity.getResources().getColor(R.color.text_assign_car_blue));
        viewHolder.tv_order_status.setTextColor(activity.getResources().getColor(R.color.text_assign_car_blue));
        if (data.getWaybillStatus() == 2) {
            viewHolder.line_left.setBackgroundColor(activity.getResources().getColor(R.color.text_assign_car_gray));
            viewHolder.tv_order_status.setTextColor(activity.getResources().getColor(R.color.text_assign_car_gray));
            viewHolder.tv_order_status.setText("待装货");
        } else if (data.getWaybillStatus() == 3) {
            viewHolder.line_left.setBackgroundColor(activity.getResources().getColor(R.color.text_assign_car_gray));
            viewHolder.tv_order_status.setTextColor(activity.getResources().getColor(R.color.text_assign_car_gray));
            viewHolder.tv_order_status.setText("装货中");
        } else if (data.getWaybillStatus() == 4) {
            viewHolder.tv_order_status.setText("运输中");
        } else if (data.getWaybillStatus() == 5) {
            viewHolder.tv_order_status.setText("卸货中");
        } else if (data.getWaybillStatus() == 6) {
            viewHolder.tv_order_status.setText("待确认收货");
        } else if (data.getWaybillStatus() == 7) {
            viewHolder.tv_order_status.setText("订单完成");
        } else if (data.getWaybillStatus() == 8) {//getWaybillStatus()
            viewHolder.tv_order_status.setText("已取消");
        }*/
        if (data.getWaybillStatus() <=3) {
            viewHolder.iv_status.setImageResource(R.mipmap.driver_before_load);
        }else  if (data.getWaybillStatus() == 4) {
            viewHolder.iv_status.setImageResource(R.mipmap.driver_transing);
        }else  if (data.getWaybillStatus() <=6) {
            viewHolder.iv_status.setImageResource(R.mipmap.driver_before_get_goods);
        }else  if (data.getWaybillStatus() == 7) {
            viewHolder.iv_status.setImageResource(R.mipmap.driver_has_complete);
        }




        viewHolder.tv_order_no.setText(data.getWaybillNo());
        viewHolder.tv_order_time.setText(data.getCreatetime());

        if (resultWaitTransEntity!=null ){
            if (resultWaitTransEntity.getStartPoint()!=null) {
                viewHolder.tv_city_start.setText(resultWaitTransEntity.getStartPoint());
            }
            if (resultWaitTransEntity.getEndPoint()!=null) {
                viewHolder.tv_city_end.setText(resultWaitTransEntity.getEndPoint());
            }

        }else {

        }





        viewHolder.tv_cenyunren.setText(data.getDriverName() + "   " + data.getPlateNumber());

       if (!StringUtil.isBlank(data.getOriginalWeight())) {
           viewHolder.tv_xiadan.setText(StringUtil.getDouble(data.getOriginalWeight() + "") + "t/"+data.getOriginalNum()+"件");

       }
        viewHolder.tv_gua_name.setVisibility(View.VISIBLE);
        if (data.getWaybillStatus() > 3) {
            viewHolder.tv_acture_weight.setText(StringUtil.getDouble(data.getWeight() + "") + "t/"+data.getSumNumber()+"件");
            viewHolder.ll_acture.setVisibility(View.VISIBLE);
            viewHolder.tv_gua_name.setVisibility(View.GONE);
            viewHolder.tv_xiadan.setVisibility(View.INVISIBLE);
        } else {
            viewHolder.ll_acture.setVisibility(View.GONE);
        }

       /* viewHolder.tv_money.setText("总价" + StringUtil.getDouble(orderEntity.getSumPrice() + ""));
        if (orderEntity.getNormalPrice() != 0) {
            viewHolder.tv_bid_price.setVisibility(View.VISIBLE);
            viewHolder.tv_bid_price.setText("挂牌" + StringUtil.getDouble(orderEntity.getNormalPrice() + ""));
        } else {
            viewHolder.tv_bid_price.setVisibility(View.GONE);
        }*/



        viewHolder.ll_div.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                if ((data.getDriverId() + "").equals(SharedPrefUtil.getUserId()) &&data.getWaybillStatus()>=3){
                if ((data.getDriverId() + "").equals(SharedPrefUtil.getUserId())){
//                    Intent intent=new Intent(activity, WaybilDetailDirverActivity.class);
                /*    Intent intent=new Intent(activity, WaybilDetailActivity.class);
                    intent.putExtra("waybilId",data.getWaybillId()+"");

                    if (resultWaitTransEntity!=null && resultWaitTransEntity.getFleetId()>0){
                        intent.putExtra("type", 6);
                    }else {
                        intent.putExtra("type", 5);
                    }
                    intent.putExtra("orderId", resultWaitTransEntity.getOrderId()+"");
                    activity.startActivity(intent);*/


                    if (resultWaitTransEntity!=null && resultWaitTransEntity.getFleetId()>0){
                        Intent intent=new Intent(activity, WaybilDetailActivity.class);
                        intent.putExtra("waybilId",data.getWaybillId()+"");
                        intent.putExtra("type", 6);
                        intent.putExtra("orderId", resultWaitTransEntity.getOrderId()+"");
                        activity.startActivity(intent);
                    }else {
                        ResultWaitTransDriver.OutDataEntity.DataEntity.PageWayBillListEntity waitTransEntity=new  ResultWaitTransDriver.OutDataEntity.DataEntity.PageWayBillListEntity();
                        waitTransEntity.setApplyNoStatus(0);
                        waitTransEntity.setOrderId(resultWaitTransEntity.getOrderId());
                        waitTransEntity.setFleetId(0);
                        waitTransEntity.setWaybillId(data.getWaybillId());
                        waitTransEntity.setContactPhone(resultWaitTransEntity.getPhoneCall());
                        Intent intent=new Intent(activity, WaybilDetailDirverActivity.class);
                        intent.putExtra("waybilId",data.getWaybillId()+"");
                        intent.putExtra("data",waitTransEntity);
                        intent.putExtra("type", 2);
                        activity.startActivity(intent);
                    }

                  /*  ResultWaitTransDriver.OutDataEntity.DataEntity.PageWayBillListEntity waitTransEntity=new  ResultWaitTransDriver.OutDataEntity.DataEntity.PageWayBillListEntity();
                    waitTransEntity.setApplyNoStatus(0);
                    waitTransEntity.setOrderId(resultWaitTransEntity.getOrderId());
                    waitTransEntity.setFleetId(0);
                    waitTransEntity.setWaybillId(data.getWaybillId());
                    waitTransEntity.setContactPhone(resultWaitTransEntity.getPhoneCall());
                    Intent intent=new Intent(activity, WaybilDetailDirverActivity.class);
                    intent.putExtra("waybilId",data.getWaybillId()+"");
                    intent.putExtra("data",waitTransEntity);
                    intent.putExtra("type", 2);
                    activity.startActivity(intent);*/

                }else {
                    Intent intent = new Intent(activity, WaybilDetailActivity.class);
//                intent.putExtra("data",data.getWaybillId()+"");
                    intent.putExtra("type", 3);
                    intent.putExtra("waybilId", data.getWaybillId() + "");
                    activity.startActivity(intent);
                }

            }
        });



        if ((data.getDriverId() + "").equals(SharedPrefUtil.getUserId())) {
            if (data.getWaybillStatus() <= 3) {
                viewHolder.tv_navi.setText("导航");
                viewHolder.tv_trans.setText("开始运输");
                viewHolder.tv_navi.setVisibility(View.GONE);
                viewHolder.tv_trans.setVisibility(View.VISIBLE);

            } else if (data.getWaybillStatus() <= 5) {
                viewHolder.tv_navi.setText("导航");
                viewHolder.tv_trans.setText("运输完成");
                viewHolder.tv_navi.setVisibility(View.VISIBLE);
                viewHolder.tv_trans.setVisibility(View.VISIBLE);
            } else if (data.getWaybillStatus() == 6) {
                viewHolder.tv_navi.setText("导航");
                viewHolder.tv_trans.setText("验证卸货");
                viewHolder.tv_navi.setVisibility(View.GONE);
                viewHolder.tv_trans.setVisibility(View.VISIBLE);
            } else if (data.getWaybillStatus() > 6) {
                viewHolder.tv_navi.setVisibility(View.GONE);
                viewHolder.tv_trans.setVisibility(View.GONE);
            }




            viewHolder.tv_navi.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    selectOrderAddress(data.getOrderId() + "");
                }
            });
            viewHolder.tv_trans.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (data.getWaybillStatus() <= 3) {
                        //开始运输
//                        startTranslate(data.getPageWayBillList().get(0));
                        startTranslate(data.getWaybillId() + "");
                    } else if (data.getWaybillStatus() <= 5) {
                        //运输完成
                        Intent intent = new Intent(activity, SureUnLoadOverActivity.class);
                        //  intent.putExtra("phone", bean.getPhone());
               /*         intent.putExtra("waybillId", data.getWaybillId());
                        intent.putExtra("fromlist", true);
                        intent.putExtra("personalOrder", false);
                        activity.startActivity(intent);*/

                        if (resultWaitTransEntity!=null  && resultWaitTransEntity.getFleetId() == 0) {
                            intent.putExtra("orederId", resultWaitTransEntity.getOrderId());
                            intent.putExtra("fromlist", true);
                            intent.putExtra("personalOrder", true);
                        } else {
                            intent.putExtra("waybillId", data.getWaybillId());
                            intent.putExtra("fromlist", true);
                            intent.putExtra("personalOrder", false);
                        }
                        activity.startActivity(intent);

                    } else if (data.getWaybillStatus() == 6) {
                        //验证卸货

                      /*  if (resultWaitTransEntity!=null) {
                            sureAcceptGood(resultWaitTransEntity.getPhoneCall(), data.getWaybillId() + "");
//                            sureAcceptGood(data.getPhone(), data.getWaybillId() + "");
                        }*/

                        if (resultWaitTransEntity!=null  && resultWaitTransEntity.getFleetId() == 0) {
                            sureAcceptGood(resultWaitTransEntity.getPhoneCall(), resultWaitTransEntity.getOrderId() + "");
                        } else {
                            sureAcceptGood(resultWaitTransEntity.getPhoneCall(), data.getWaybillId() + "");

                        }



                    } else {

                    }
                }
            });
        } else {
            viewHolder.tv_navi.setVisibility(View.GONE);
            viewHolder.tv_trans.setVisibility(View.GONE);
        }


        viewHolder.tv_bid_price.setVisibility(View.INVISIBLE);
        viewHolder.tv_money.setVisibility(View.INVISIBLE);
        return convertView;
    }

    private void setGoodName(TextView view, List<ResultMoneyFollow.OutData.MiddleData.InnderData.WaybillsBean> goodnames) {
        StringBuilder builder = new StringBuilder();
        for (ResultMoneyFollow.OutData.MiddleData.InnderData.WaybillsBean info : goodnames) {
            builder.append(info.getGoodsName() + ",");
        }
        String temp = builder.toString();
        String result = temp.substring(0, temp.length() - 1);
        view.setText(result);
    }



    class ViewHolder {
//        View line_left;
//        TextView tv_order_status;
        ImageView iv_status;


        TextView tv_order_no;
        TextView tv_order_time;
        TextView tv_city_start;
        TextView tv_city_end;
        //        TextView tv_goods_name;
//        TextView tv_weight;
        TextView tv_cenyunren;
        TextView tv_acture_weight;
        TextView tv_money;
        TextView tv_bid_price;
        LinearLayout ll_acture;
        LinearLayout ll_div;
        TextView tv_xiadan;
        TextView tv_navi;
        TextView tv_trans;
        TextView tv_gua_name;
    }

    @Override
    public boolean getSwipEnableByPosition(int position) {
//            if(position % 2 == 0){
//                return false;
//            }
        return true;
    }


    /**
     * 导航请求数据
     *
     * @param id
     */
    private void selectOrderAddress(String id) {
        DialogUtil.showLoadingDialog(activity, "请求中...");
        Map<String, String> params = new HashMap<String, String>();
        params.put("orderId", id);
        MyHttpUtil.selectOrderAddress(activity, params, new MyCallback<OrderAddressResult>(activity, new JsonGenericsSerializator()) {
            @Override
            public void onFail(Call call, Exception e, int id) {
                PrintUtil.toast(activity, "网络异常，请稍后再试");
                e.printStackTrace();
            }

            @Override
            public void onSuccess(OrderAddressResult result, int id) {
                if (result.getCode() == ConstUtil.OK) {
                    Intent intent = new Intent(activity, BeforeNaviActivity.class);
                    intent.putExtra("OrderAddressResult", result);
                    activity.startActivity(intent);
                } else {
                    PrintUtil.toast(activity, result.getMsg());
                }
            }
        });
    }

    private void startTranslate(String waybillId) {
        DialogUtil.showLoadingDialog(activity, "请求中...");
        Map<String, String> params = new HashMap<String, String>();
        params.put("waybillId", waybillId + "");
        params.put("waybillStatus", "4");
        params.put("driverId", SharedPrefUtil.getUserId());
        MyHttpUtil.startTranslate(activity, params, new MyCallback<Result>(activity, new JsonGenericsSerializator()) {
            @Override
            public void onFail(Call call, Exception e, int id) {
                PrintUtil.toast(activity, "网络异常，请稍后再试");
                e.printStackTrace();
            }

            @Override
            public void onSuccess(Result result, int id) {
                if (result.getCode() == ConstUtil.OK) {
                    EventBusUtil.postEvent(new RefleshFragEvent(3));
                } else {
                    PrintUtil.toast(activity, result.getMsg());
                }
            }
        });


    }


    /**
     * 验证卸货
     *
     * @param phone id
     */
    public void sureAcceptGood(final String phone, final String id) {
        if (StringUtil.isBlank(phone)) {
            PrintUtil.toast(activity, "收货人电话为空");
            return;
        }
        if (null == alertDialog) {
            alertDialog = new AlertDialog.Builder(activity).create();
            alertDialog.show();
            alertDialog.setTitle(null);
            alertDialog.setCanceledOnTouchOutside(false);
            alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                    // TODO Auto-generated method stub
                    alertDialog = null;
                }
            });
            Window window = alertDialog.getWindow();
            window.setGravity(Gravity.CENTER);
            window.setBackgroundDrawable(new ColorDrawable(0));
            window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            window.setContentView(R.layout.dialog_sureunload);
            View view = window.getDecorView();
            et_sureunload_code = (EditText) view.findViewById(R.id.et_sureunload_code);
            tv_cancle_unload = (TextView) view.findViewById(R.id.tv_cancle_unload);
            tv_sureunload_getcode = (TextView) view.findViewById(R.id.tv_sureunload_getcode);
            tv_sure_unload = (TextView) view.findViewById(R.id.tv_sure_unload);
            alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    validateOk = false;

                }
            });
            tv_cancle_unload.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    alertDialog.dismiss();
                    alertDialog = null;
                }
            });
            tv_sureunload_getcode.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!validateOk) {//获取成功验证码 且对话框没消失时无法多次点击
                        getValidateCode(phone, id);
                    } else {

                        PrintUtil.toast(activity, "验证码已发送给货主！");
                    }
                }
            });
            tv_sure_unload.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (TextUtils.isEmpty(et_sureunload_code.getText().toString().trim())) {
                        PrintUtil.toast(activity, "请填写获取到验证码");
                        return;
                    }

                    if (!validateOk){
                        PrintUtil.toast(activity,"请先获取验证码");
                        return;
                    }
                    Message message = Message.obtain();
                    message.obj = id;
                    if (resultWaitTransEntity!=null  && resultWaitTransEntity.getFleetId() == 0) {
                        message.what = 2;
                    } else {
                        message.what = 1;
                    }

                    mHandler.sendMessage(message);
//                    alertDialog.dismiss();
//                    alertDialog = null;
                }
            });
        }
        //下面两行代码加入后即可弹出输入法
        alertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    }


    /**
     * 获取验证码
     */
    private void getValidateCode(String phone, String id) {
        DialogUtil.showLoadingDialog(activity, "加载中...");
        Map<String, String> params = new HashMap<String, String>();
        params.put("phone", phone);
        params.put("validateMsg", id);
        MyHttpUtil.getSureValidateCode(activity, params, new MyCallback<ValidateCodeResult>(activity, new JsonGenericsSerializator()) {
            @Override
            public void onFail(Call call, Exception e, int id) {
                e.printStackTrace();
                PrintUtil.toast(activity, "网络异常，请稍后再试");
            }

            @Override
            public void onSuccess(ValidateCodeResult result, int id) {
                if (result.getCode() == ConstUtil.OK) {
                    validateOk = true;
                    tv_sureunload_getcode.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.tv_shape_gray_round_corner_solid));
                } else {
                    PrintUtil.toast(activity, result.getMsg());
                }
            }
        });


    }







    /**
     * 收货完成 （传入订单id或者运单id）
     */
    private void updateWaybillUnload(String waybilOrOrderId,final boolean iswaybill) {
        DialogUtil.showLoadingDialog(activity, "加载中...");
        Map<String, String> params = new HashMap<String, String>();
        if (iswaybill) {
            params.put("waybillId", waybilOrOrderId);
        } else {
            params.put("orderId", waybilOrOrderId);
        }
        params.put("waybillStatus", "7");
        params.put("validateMsg", waybilOrOrderId + "");
        params.put("validateCode", et_sureunload_code.getText().toString().trim());
        MyHttpUtil.updateWaybillStatus(activity, params, new MyCallback<Result>(activity, new JsonGenericsSerializator()) {
            @Override
            public void onFail(Call call, Exception e, int id) {
                e.printStackTrace();
                PrintUtil.toast(activity, "网络异常，请稍后再试");
            }

            @Override
            public void onSuccess(Result result, int id) {
                if (result.getCode() == ConstUtil.OK) {
                    PrintUtil.toast(activity, "您已替货主确认收货");
                    EventBusUtil.postEvent(new RefleshFragEvent(3));
                    alertDialog.dismiss();
                    alertDialog = null;
                } else {
                    if (result.getMsg()!=null){
                        PrintUtil.toast(activity,result.getMsg());
                    }else {
                        PrintUtil.toast(activity,"操作失败");
                    }
                }
            }
        });


    }



    /**
     * 代替货主收货接口 (个人订单时)
     */
    private void updteOrderUnload(String orderId) {
        DialogUtil.showLoadingDialog(activity,"请求中...");
        Map<String,String> params=new HashMap<String, String>();
        if (files == null) {
            files = new ArrayList();
        }
        params.clear();
        params.put("orderId", orderId + "");
        params.put("orderStatus", "7");
        params.put("validateMsg", orderId + "");
        params.put("validateCode", et_sureunload_code.getText().toString().trim());
        MyHttpUtil.updateOrderUnload(activity,files,params, new MyCallback<Result>(activity,new JsonGenericsSerializator()) {
            @Override
            public void onFail(Call call, Exception e, int id) {
                e.printStackTrace();
                PrintUtil.toast(activity, "网络异常，请稍后再试");
            }
            @Override
            public void onSuccess(Result result, int id) {
                if (result.getCode() == ConstUtil.OK) {
                    PrintUtil.toast(activity, "您已替货主确认收货");
                    EventBusUtil.postEvent(new RefleshFragEvent(3));
                    alertDialog.dismiss();
                    alertDialog = null;
                }else{
                    PrintUtil.toast(activity,result.getMsg());
                }
            }
        });
    }

}
